﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Gene_Explorer_Client
{
    public partial class OrderWizardDataProcessing : Form
    {
        public bool checkBoxFilteringFlag = false;
        public bool checkBoxImputationFlag = false;
        public bool checkBoxTransformationFlag = false;
        public bool logFlag = false;

        public OrderWizardDataProcessing()
        {
            InitializeComponent();
        }

        private void button_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void OrderWizardDataProcessing_Load(object sender, EventArgs e)
        {

        }

        private void button_Next_Click(object sender, EventArgs e)
        {
            this.Hide();
            GlobalVariable.orderWDP = this;
            OrderWizardCluster oWC = new OrderWizardCluster();
            oWC.Show();
        }

        private void button_Back_Click(object sender, EventArgs e)
        {
            this.Hide();
            GlobalVariable.orderWDP = this;
     //       this.Close();
            OrderWizardSelectDataSet oWSD = new OrderWizardSelectDataSet();
        //  oWSD.ShowDialog();
            oWSD = GlobalVariable.orderWSD;
    //      oWSD.Visible = false;
     //     oWSD.Close();
            oWSD.Show();
            //无法访问已释放的对象。
            // oWSD.Visible = true;
            //已经可见的窗体不能显示为模式对话框。在调用 showDialog 之前应将窗体的 Visible 属性设置为 false。
            //已进行模式显示的窗体不能显示为模式对话框。请在调用 showDialog 之前关闭该窗体。
        }

        private void checkBox_Filtering_CheckedChanged(object sender, EventArgs e)
        {
            //checkBox_LosePercent  checkBox_MinSD  checkBox_MaxMin  checkBox_Threshold
            //textBox_LosePercent  textBox_MinSD  textBox_MaxMin  textBox_Threshold  textBox_Number  label2 label1
            checkBox_MinSD.Enabled = !checkBox_MinSD.Enabled;
            checkBox_MaxMin.Enabled = !checkBox_MaxMin.Enabled;
            checkBox_Threshold.Enabled = !checkBox_Threshold.Enabled;
            checkBox_LosePercent.Enabled = !checkBox_LosePercent.Enabled;
            checkBox_Entropy.Enabled = !checkBox_Entropy.Enabled;
            checkBox_EmptyGene.Enabled = !checkBox_EmptyGene.Enabled;
            if (checkBox_LosePercent.Checked == true)
            {
                label1.Enabled = !label1.Enabled;
                textBox_LosePercent.Enabled = !textBox_LosePercent.Enabled;
                
            }
            if (checkBox_MinSD.Checked == true)
            {
                textBox_MinSD.Enabled = !textBox_MinSD.Enabled;   
            }
            if (checkBox_Entropy.Checked == true)
            {
                textBox_Entropy.Enabled = !textBox_Entropy.Enabled;
                label9.Enabled = !label9.Enabled;
            }
            if (checkBox_MaxMin.Checked == true)
            {
                textBox_MaxMin.Enabled = !textBox_MaxMin.Enabled;  
            }
            if (checkBox_Threshold.Checked == true)
            {
                textBox_Threshold.Enabled = !textBox_Threshold.Enabled;
                textBox_Number.Enabled = !textBox_Number.Enabled;
                label2.Enabled = !label2.Enabled;
            }
            /*
            if (checkBoxFilteringFlag == false)
            {
                checkBox_LosePercent.Enabled = true;
                checkBox_MinSD.Enabled = true;
                checkBox_MaxMin.Enabled = true;
                checkBox_Threshold.Enabled = true;
                textBox_LosePercent.Enabled = true;
                textBox_MinSD.Enabled = true;
                textBox_MaxMin.Enabled = true;
                textBox_Threshold.Enabled = true;
                textBox_Number.Enabled = true;
                label2.Enabled = true;
                label1.Enabled = true;
            }
            else
            {
                checkBox_LosePercent.Enabled = false;
                checkBox_MinSD.Enabled = false;
                checkBox_MaxMin.Enabled = false;
                checkBox_Threshold.Enabled = false;
                textBox_LosePercent.Enabled = false;
                textBox_MinSD.Enabled = false;
                textBox_MaxMin.Enabled = false;
                textBox_Threshold.Enabled = false;
                textBox_Number.Enabled = false;
                label2.Enabled = false;
                label1.Enabled = false;
            }
            checkBoxFilteringFlag = !checkBoxFilteringFlag;
             */ 
        }

        private void checkBox_Imputation_CheckedChanged(object sender, EventArgs e)
        {
            //label3 label4 label5 label7
            //comboBox_InputationMethod  comboBox_AverageMethod   textBox_K  comboBox_DistanceMeasure

            label3.Enabled = !label3.Enabled;
            comboBox_InputationMethod.Enabled = !comboBox_InputationMethod.Enabled;
            if (comboBox_InputationMethod.SelectedIndex == 1 || comboBox_InputationMethod.SelectedIndex == 2)
            {
                label7.Enabled = !label7.Enabled;
                comboBox_AverageMethod.Enabled = !comboBox_AverageMethod.Enabled;
            }
            if (comboBox_InputationMethod.SelectedIndex == 3)
            {
                label7.Enabled = !label7.Enabled;
                comboBox_AverageMethod.Enabled = !comboBox_AverageMethod.Enabled;
                label4.Enabled = !label4.Enabled;
                label5.Enabled = !label5.Enabled;
                textBox_K.Enabled = !textBox_K.Enabled;
                comboBox_DistanceMeasure.Enabled = !comboBox_DistanceMeasure.Enabled;
                if (comboBox_DistanceMeasure.SelectedIndex == 2)
                {
                    label8.Enabled = !label8.Enabled;
                    comboBox_Power.Enabled = !comboBox_Power.Enabled;
                }
            }
            /*
            if (checkBoxImputationFlag == false)
            {
                label3.Enabled = true;
                label4.Enabled = true;
                label5.Enabled = true;
                label7.Enabled = true;
                comboBox_InputationMethod.Enabled = true;
                comboBox_AverageMethod.Enabled = true;
                textBox_K.Enabled = true;
                comboBox_DistanceMeasure.Enabled = true;
            }
            else
            {
                label3.Enabled = false;
                label4.Enabled = false;
                label5.Enabled = false;
                label7.Enabled = false;
                comboBox_InputationMethod.Enabled = false;
                comboBox_AverageMethod.Enabled = false;
                textBox_K.Enabled = false;
                comboBox_DistanceMeasure.Enabled = false;
            }
            checkBoxImputationFlag = !checkBoxImputationFlag;
             */
        }

        private void checkBox_Transformation_CheckedChanged(object sender, EventArgs e)
        {
            // radioButton_Norm  radioButton_Log  comboBox_Log label6  textBox_X
            radioButton_Norm.Enabled = !radioButton_Norm.Enabled;
            radioButton_Log.Enabled = !radioButton_Log.Enabled;
            if (radioButton_Log.Checked == true)
            {
                comboBox_Log.Enabled = !comboBox_Log.Enabled;
                if (comboBox_Log.SelectedIndex == 3)
                {
                    label6.Enabled = !label6.Enabled;
                    textBox_X.Enabled = !textBox_X.Enabled;
                }
            }
             
            /*
            if (checkBoxTransformationFlag == false)
            {
                radioButton_Norm.Enabled = true;
                radioButton_Log.Enabled = true;
                comboBox_Log.Enabled = false;
                label6.Enabled = false;
                textBox_X.Enabled = false;
            }
            else
            {
                radioButton_Norm.Enabled = false;
                radioButton_Log.Enabled = false;
                comboBox_Log.Enabled = false;
                label6.Enabled = false;
                textBox_X.Enabled = false;
            }
            checkBoxTransformationFlag = !checkBoxTransformationFlag;
             */ 
        }

        private void radioButton_Log_CheckedChanged(object sender, EventArgs e)
        {

            comboBox_Log.Enabled = !comboBox_Log.Enabled;
            if (comboBox_Log.SelectedIndex == 3)
            {
                label6.Enabled = !label6.Enabled;
                textBox_X.Enabled = !textBox_X.Enabled;
            }
            //if (logFlag == false)
            //{
            //    comboBox_Log.Enabled = true;
            //  //  label6.Enabled = true;
            //  //  textBox_X.Enabled = true;
            //}
            //else
            //{
            //    comboBox_Log.Enabled = false;
            // //   label6.Enabled = false;
            // //   textBox_X.Enabled = false;
            //}
            //logFlag = !logFlag;
            
        }

        private void comboBox_Log_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox_Log.SelectedIndex == 3)
            {
                label6.Enabled = true;
                textBox_X.Enabled = true;
            }
            else
            {
                label6.Enabled = false;
                textBox_X.Enabled = false;
            }
        }

        private void comboBox_DistanceMeasure_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox_DistanceMeasure.SelectedIndex == 2)
            {
                label8.Enabled = true;
                comboBox_Power.Enabled = true;
            }
            else
            {
                label8.Enabled = false;
                comboBox_Power.Enabled = false;
            }
        }

        private void comboBox_InputationMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox_InputationMethod.SelectedIndex)
            {
                case 0:
                    label7.Enabled = false;
                    comboBox_AverageMethod.Enabled = false;
                    label4.Enabled = false;
                    label5.Enabled = false;
                    textBox_K.Enabled = false;
                    comboBox_DistanceMeasure.Enabled = false;
                    label8.Enabled = false;
                    comboBox_Power.Enabled = false;
                    break;
                case 1:
                    label7.Enabled = true;
                    comboBox_AverageMethod.Enabled = true;
                    label4.Enabled = false;
                    label5.Enabled = false;
                    textBox_K.Enabled = false;
                    comboBox_DistanceMeasure.Enabled = false;
                    label8.Enabled = false;
                    comboBox_Power.Enabled = false;
                    break;
                case 2:
                    label7.Enabled = true;
                    comboBox_AverageMethod.Enabled = true;
                    label4.Enabled = false;
                    label5.Enabled = false;
                    textBox_K.Enabled = false;
                    comboBox_DistanceMeasure.Enabled = false;
                    label8.Enabled = false;
                    comboBox_Power.Enabled = false;
                    break;
                case 3:
                    label7.Enabled = true;
                    comboBox_AverageMethod.Enabled = true;
                    label4.Enabled = true;
                    label5.Enabled = true;
                    textBox_K.Enabled = true;
                    comboBox_DistanceMeasure.Enabled = true;
                    label8.Enabled = false;
                    comboBox_Power.Enabled = false;
                    break;
                default:
                    break;

            }

            //if (comboBox_InputationMethod.SelectedIndex != 0)
            //{
            //    label7.Enabled = !label7.Enabled;
            //    comboBox_AverageMethod.Enabled = !comboBox_AverageMethod.Enabled;
            //    if (comboBox_InputationMethod.SelectedIndex == 3)
            //    {
            //        label4.Enabled = !label4.Enabled;
            //        label5.Enabled = !label5.Enabled;
            //        textBox_K.Enabled = !textBox_K.Enabled;
            //        comboBox_DistanceMeasure.Enabled = !comboBox_DistanceMeasure.Enabled;
            //        if (comboBox_DistanceMeasure.SelectedIndex == 2)
            //        {
            //            label8.Enabled = !label8.Enabled;
            //            comboBox_Power.Enabled = !comboBox_Power.Enabled;
            //        }
            //    }
            //}
        }

        private void checkBox_LosePercent_CheckedChanged(object sender, EventArgs e)
        {
            label1.Enabled = !label1.Enabled;
            textBox_LosePercent.Enabled = !textBox_LosePercent.Enabled;
  
        }

        private void checkBox_MinSD_CheckedChanged(object sender, EventArgs e)
        {
            textBox_MinSD.Enabled = !textBox_MinSD.Enabled;  
        }

        private void checkBox_MaxMin_CheckedChanged(object sender, EventArgs e)
        {
            textBox_MaxMin.Enabled = !textBox_MaxMin.Enabled;  
        }

        private void checkBox_Threshold_CheckedChanged(object sender, EventArgs e)
        {
            textBox_Threshold.Enabled = !textBox_Threshold.Enabled;
            textBox_Number.Enabled = !textBox_Number.Enabled;
            label2.Enabled = !label2.Enabled;
        }

        private void textBox_Number_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
            if (e.KeyChar == (char)8)
            {
                e.Handled = false;
            }
        }

        private void textBox_K_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
            if (e.KeyChar == (char)8)
            {
                e.Handled = false;
            }
        }

        private void textBox_LosePercent_KeyPress(object sender, KeyPressEventArgs e)
        {
            string str = this.textBox_LosePercent.Text;
            e.Handled = e.KeyChar < '0' || e.KeyChar > '9';   
            if (e.KeyChar == (char)8)   
            {
                e.Handled = false;
            }
            if (e.KeyChar == (char)46)
            {
                if (str == "")   
                {
                    e.Handled = true;
                    return;
                }
                else
                { 
                    foreach (char ch in str)
                    {
                        if (char.IsPunctuation(ch))
                        {
                            e.Handled = true;
                            
                            return;
                        }
                    }
                    e.Handled = false;
                }
            }
        }

        private void textBox_MinSD_KeyPress(object sender, KeyPressEventArgs e)
        {
            string str = this.textBox_MinSD.Text;
            e.Handled = e.KeyChar < '0' || e.KeyChar > '9';   
            if (e.KeyChar == (char)8)   
            {
                e.Handled = false;
            }
            if (e.KeyChar == (char)46)
            {
                if (str == "")   
                {
                    e.Handled = true;
                    return;
                }
                else
                { 
                    foreach (char ch in str)
                    {
                        if (char.IsPunctuation(ch))
                        {
                            e.Handled = true;
                            
                            return;
                        }
                    }
                    e.Handled = false;
                }
            }
        }

        private void textBox_MaxMin_KeyPress(object sender, KeyPressEventArgs e)
        {
            string str = this.textBox_MaxMin.Text;
            e.Handled = e.KeyChar < '0' || e.KeyChar > '9';   
            if (e.KeyChar == (char)8)   
            {
                e.Handled = false;
            }
            if (e.KeyChar == (char)46)
            {
                if (str == "")   
                {
                    e.Handled = true;
                    return;
                }
                else
                { 
                    foreach (char ch in str)
                    {
                        if (char.IsPunctuation(ch))
                        {
                            e.Handled = true;                            
                            return;
                        }
                    }
                    e.Handled = false;
                }
            }
        }

        private void textBox_Threshold_KeyPress(object sender, KeyPressEventArgs e)
        {
            string str = this.textBox_Threshold.Text;
            e.Handled = e.KeyChar < '0' || e.KeyChar > '9';   
            if (e.KeyChar == (char)8)  
            {
                e.Handled = false;
            }
            if (e.KeyChar == (char)46)
            {
                if (str == "")   
                {
                    e.Handled = true;
                    return;
                }
                else
                { 
                    foreach (char ch in str)
                    {
                        if (char.IsPunctuation(ch))
                        {
                            e.Handled = true;                            
                            return;
                        }
                    }
                    e.Handled = false;
                }
            }
        }

        private void textBox_X_KeyPress(object sender, KeyPressEventArgs e)
        {
            string str = this.textBox_X.Text;
            e.Handled = e.KeyChar < '0' || e.KeyChar > '9';   
            if (e.KeyChar == (char)8)   
            {
                e.Handled = false;
            }
            if (e.KeyChar == (char)46)
            {
                if (str == "")   
                {
                    e.Handled = true;
                    return;
                }
                else
                { 
                    foreach (char ch in str)
                    {
                        if (char.IsPunctuation(ch))
                        {
                            e.Handled = true;                            
                            return;
                        }
                    }
                    e.Handled = false;
                }
            }
        }

        private void checkBox_Entropy_CheckedChanged(object sender, EventArgs e)
        {
            textBox_Entropy.Enabled = !textBox_Entropy.Enabled;
            label9.Enabled = !label9.Enabled;
        }

    }
}
